/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cjava.system.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author user
 */
@Entity
@Table(name = "system_user", catalog = "socioscjava", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SystemUser.findAll", query = "SELECT s FROM SystemUser s")})
public class SystemUser implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "user_name")
    private String userName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "password")
    private String password;
    @Column(name = "finish_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date finishDate;
    @Basic(optional = false)
    @NotNull
    @Column(name="type")
    private String type;
    @Column(name="description")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idSystemUser")
    private List<BusinessAssociate> businessAssociatesList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "systemUserId")
    private List<Company> companyList;
    @Transient
    private int paint;

    public SystemUser() {
    }

    public SystemUser(Integer id) {
        this.id = id;
    }

    public SystemUser(Integer id, String userName, String password) {
        this.id = id;
        this.userName = userName;
        this.password = password;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(Date finishDate) {
        this.finishDate = finishDate;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPaint() {
        if(this.finishDate != null) {
            Calendar hoy = Calendar.getInstance();
            hoy.set(Calendar.HOUR, 0);
            hoy.set(Calendar.MINUTE, 0);
            hoy.set(Calendar.SECOND, 0);
            Calendar calDate = Calendar.getInstance();
            calDate.setTime(finishDate);
            calDate.set(Calendar.HOUR, 0);
            calDate.set(Calendar.MINUTE, 0);
            calDate.set(Calendar.SECOND, 0);
            //si calDate < cal = false;
            if(hoy.before(calDate)) {
                paint = 1; // aun estan activos
            } else {
                paint = 0; // ya vencieron
            }
        }
        return paint;
    }

    public void setPaint(int paint) {
        this.paint = paint;
    }

    @XmlTransient
    public List<BusinessAssociate> getBusinessAssociatesList() {
        return businessAssociatesList;
    }

    public void setBusinessAssociatesList(List<BusinessAssociate> businessAssociatesList) {
        this.businessAssociatesList = businessAssociatesList;
    }

    public List<Company> getCompanyList() {
        return companyList;
    }

    public void setCompanyList(List<Company> companyList) {
        this.companyList = companyList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SystemUser)) {
            return false;
        }
        SystemUser other = (SystemUser) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.cjava.system.model.SystemUser[ id=" + id + " ]";
    }
    
}
